package com.itheima.jods;

import com.itheima.constant.RedisConst;
import com.itheima.utils.QiniuUtils;
import org.springframework.beans.factory.annotation.Autowired;
import redis.clients.jedis.JedisPool;

import java.util.Date;
import java.util.Set;

/**
 * ClassName: CleanJobs
 * Description:
 * date: 2019/11/22 18:12
 * Author Airson
 * Since JDK 1.8
 */
public class CleanJobs {

    @Autowired
    JedisPool jedisPool;

    public void cleanimg() {
        System.out.println("执行定时任务"+new Date());
        //获取redis中垃圾文件的名称
        Set<String> sdiff = jedisPool.getResource().sdiff(RedisConst.SETMEAL_PIC_RESOURCES, RedisConst.SETMEAL_PIC_DB_RESOURCES);
        System.out.println(sdiff.size());
        for (String s : sdiff) {
            //删除七牛云中的图片
            QiniuUtils.deleteFileFromQiniu(s);
            //删除redis中的垃圾文件
            jedisPool.getResource().srem(RedisConst.SETMEAL_PIC_RESOURCES, s);

            System.out.println("定时任务删除了:"+s);
        }
    }
}
